// Created: Dec 14, 2014
//
// Author: wjinwen.1988@gmail.com

#ifndef CHI_NET_EVENT_LOOP_THREAD_POOL_H
#define CHI_NET_EVENT_LOOP_THREAD_POOL_H

#include <vector>
#include <functional>

#include "chi/mutex.h"
#include "chi/condition.h"

namespace chi {
namespace net {

class EventLoop;
class EventLoopThread;

class EventLoopThreadPool {
 public:
  using ThreadInitCallback = std::function<void (EventLoop*)>;

  EventLoopThreadPool(EventLoop* base_loop);
  ~EventLoopThreadPool();

  EventLoopThreadPool(const EventLoopThreadPool&) = delete;
  void operator=(const EventLoopThreadPool&) = delete;

  void set_num_threads(int num_threads) { num_threads_ = num_threads; }
  void Start(const ThreadInitCallback& cb = ThreadInitCallback());
  EventLoop* GetNextLoop();
 private:
  EventLoop* base_loop_;
  bool started_;
  int num_threads_;
  int next_;
  std::vector<EventLoopThread*> threads_;
  std::vector<EventLoop*> loops_;
};

}  
}

#endif
